function out=f_runNN_Kfold(hiddenlayers,All_vectors,Kfold)
N_class = length(All_vectors);

% size(All_vectors{1})
X_features=[]; Y=[];
for iclass = 1:N_class
    y_label = [];
    tar=zeros(1,N_class);
    tar(1,iclass)=1;
    for i=1:size(All_vectors{iclass},1)
        y_label(i,:)=tar;
    end
    Y =[Y
        y_label];
    X_features = [X_features;All_vectors{iclass}];
end
pause(0.1)
% ====== split training, validation and testing====
% Y = Y';
% X_features = X_features';
out.CM=zeros(N_class,N_class);
% out.CM_train=zeros(N_class,N_class);
% === kfold
indices = crossvalind('Kfold',Y(:,1),Kfold);
% indices
% === kfold
model = fitnet(hiddenlayers,'trainbr');
model.trainParam.showWindow = false;
for ifold = 1:Kfold
%     ifold
    testInd = (indices == ifold);
    trainInd = ~testInd;
    %     [trainInd,valInd,testInd] = dividerand(length(Y),1-testP,0,testP);
    X_train = X_features(trainInd,:)';
    X_test = X_features(testInd,:)';
    y_train = Y(trainInd,:)';
    y_test = Y(testInd,:)';
    [model tr] = train(model, X_train,y_train);
    %     map_record(ifold,:)=model.IW{1}(1,:);
    pred = model(X_test);
    %     pred_train = model(X_train);
    [c,CM] = confusion(y_test,pred);
    %     [c2,CM_train] = confusion(y_train,pred_train);
    out.CM=out.CM+CM;
    %     out.CM_train=out.CM_train+CM_train;
end
% out.CM=out.CM./Kfold;
out.CM=out.CM./100;
% out.CM_train = out.CM_train./Kfold;
out.PC = sum(diag(out.CM))./sum(sum(out.CM));
% out.PC_train = sum(diag(out.CM_train))./sum(sum(out.CM_train));
%     f_plot_heatmap(31,mean(map_record),1,1,0)
%     pause


